

void UI_DlgOptionsVariables::init() {
    graphic = NULL;

    // variables
    tabVariables->verticalHeader()->hide();
    tabVariables->verticalHeader()->setFixedWidth(0);
    tabVariables->setColumnReadOnly(0, true);
    tabVariables->setColumnReadOnly(1, true);
    tabVariables->setColumnReadOnly(2, true);
}


/**
 * Sets the graphic and updates the GUI to match the drawing.
 */
void UI_DlgOptionsVariables::setGraphic(PF_Graphic* g) {
    graphic = g;
    updateVariables();
}


/**
 * Updates the Variables tab from the graphic values.
 */
void UI_DlgOptionsVariables::updateVariables() {
    if (graphic==NULL) {
        return;
    }
    
    QVector<int> r(tabVariables->numRows());
    for (int i=0; i<tabVariables->numRows(); ++i) {
        r[i] = i;
    }
    tabVariables->removeRows(r);
    QHash<QString, PF_Variable>vars = graphic->getVariableDict();
    QHash<QString, PF_Variable>::iterator it = vars.begin();
    while (it != vars.end()) {
        tabVariables->insertRows(tabVariables->numRows(), 1);
        
        tabVariables->setText(tabVariables->numRows()-1, 0, it.key());
        tabVariables->setText(tabVariables->numRows()-1, 1, QString("%1").arg(it.value().getCode()));
        QString str = "";
        switch (it.value().getType()) {
            case LX_Define::VariableVoid:
                break;
            case LX_Define::VariableInt:
                str = QString("%1").arg(it.value().getInt());
                break;
            case LX_Define::VariableDouble:
                str = QString("%1").arg(it.value().getDouble());
                break;
            case LX_Define::VariableString:
                str = QString("%1").arg(it.value().getString());
                break;
            case LX_Define::VariableVector:
                str = QString("%1/%2")
                      .arg(it.value().getVector().x)
                      .arg(it.value().getVector().y);
                if (PF_FilterDXF::isVariableTwoDimensional(it.key())==false) {
                    str+= QString("/%1").arg(it.value().getVector().z);
                }
                break;
        }
        tabVariables->setText(tabVariables->numRows()-1, 2, str);
        ++it;
    }
}
